import { reqGoodsDetailInfoData } from '@/api'

const state = {
  goodsDetailInfo: {}
}
const actions = {
  async getGoodsDetailInfoData({ commit }, id) {
    const result = await reqGoodsDetailInfoData(id)
    if (result.code === 200) {
    console.log(result.data)
    commit('SAVE_GOOD_DETAIL_INFO_DATA',result.data)
    } else {
      console.log(result.message);
    }
  }
}
const mutations = {
  SAVE_GOOD_DETAIL_INFO_DATA(state,payload) {
    state.goodsDetailInfo = payload // 是个对象形式
  },
    // 2. 更改放大镜图片的默认图片链接
    UPDATE_IMG_DEFAULT_URL(state,imgUrl) {
      state.goodsDetailInfo.skuInfo.skuDefaultImg = imgUrl
    }
}
const getters = {
  categoryView(state) {
    return state.goodsDetailInfo.categoryView || {};
  },
  skuInfo(state) {
    return state.goodsDetailInfo.skuInfo || {}
  },
  spuSaleAttrList(state) {
    return state.goodsDetailInfo.spuSaleAttrList || {}
  }
}

export default {
  namespaced: true, // 开启命名空间
  state,
  actions,
  mutations,
  getters
}